package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.CustomerTransferHistory;
import cn.wolfcode.crm.domain.JsonResult;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.ICustomerTransferHistoryService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/customerTransferHistory")
public class CustomeTransferHistoryController {
    @Autowired
    private ICustomerTransferHistoryService customerTransferHistoryService;

    @RequestMapping("/list")
    public String list(Model model, QueryObject queryObject) {
        PageInfo result = customerTransferHistoryService.query(queryObject);
        model.addAttribute("pageInfo", result);
        model.addAttribute("qo", queryObject);
        return "customerTransferHistory/list";
    }

    @RequestMapping("/input")
    public String input(Model model, Long id) {
        if (id != null) {
            model.addAttribute("customerTransferHistory", customerTransferHistoryService.get(id));
        }
        return "customerTransferHistory/input";
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public JsonResult save(CustomerTransferHistory customerTransferHistory) {
        try {
                customerTransferHistoryService.save(customerTransferHistory);
        } catch (Exception e) {
            return new JsonResult(false, "操作失败");
        }
        return new JsonResult(true, "操作成功");
    }

}
